package cn.wolfcode.service.impl;

import cn.wolfcode.domain.NoticeItem;
import cn.wolfcode.mapper.NoticeItemMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.INoticeItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeItemServiceImpl implements INoticeItemService {

    @Autowired
    private NoticeItemMapper noticeItemMapper;


    @Override
    public void save(NoticeItem noticeItem) {
        noticeItemMapper.insert(noticeItem);
    }

    @Override
    public void delete(Long id) {
        noticeItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(NoticeItem noticeItem) {
        noticeItemMapper.updateByPrimaryKey(noticeItem);
    }

    @Override
    public NoticeItem get(Long id) {
        return noticeItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<NoticeItem> listAll() {
        return noticeItemMapper.selectAll();
    }

    @Override
    public PageInfo<NoticeItem> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<NoticeItem> noticeItems = noticeItemMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<NoticeItem>(noticeItems);
    }
}
